package com.yinhai.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import com.androidquery.AQuery;
import com.yinhai.activity.R;
import com.yinhai.model.Contactsphone;

public class ContactsphoneListAdapter extends BaseAdapter {
	private ArrayList<Contactsphone> dataList;
	private LayoutInflater layoutInflater;
	private Context context;
	private int Isdel=0;
	public ContactsphoneListAdapter(Context context,int Isdel){
		this.context=context;
		this.dataList=new ArrayList<Contactsphone>();
		this.layoutInflater=LayoutInflater.from(this.context);
		this.Isdel = Isdel;
	}
	
	public void addItem(Contactsphone item){
		dataList.add(item);
	}
	
	public void clear(){
		dataList.clear();
	}
	public void removeId(int index){
		dataList.remove(index);
	}
	
	@Override
	public int getCount() {
		return dataList.size();
	}

	@Override
	public Contactsphone getItem(int position) {
		return dataList.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if (convertView==null) {
			convertView = layoutInflater.inflate(R.layout.contacts_list_item, null);
		}
		AQuery aq = new AQuery(convertView);
		Contactsphone u = getItem(position);
		if(u !=null){
			aq.id(R.id.contacts_phonetime).text("备份时间:"+u.getContactsName());
			aq.id(R.id.contacts_conut).text("联系人数目:"+u.getConut());
			if(Isdel==0){
				aq.id(R.id.contacts_del).gone();
			}else{
				aq.id(R.id.contacts_del).visible();
			}
		}
		
		
		return convertView;
	}
}
